//
//@File    :	7.4_lotto.cpp
//@Time    :	2021/08/09 17:20:40
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	probability of winning
//

#include <iostream>
//Note some impementationgs requirs double instead of long double
long double probability(unsigned numbers,unsigned picks);
using namespace std;
int main()
{
    double total,choices;
    cout<<"Enter the total number od choices on the game card and\n"
          "the number of picks allowed:\n";
    while ((cin>>total>>choices) && choices<=total)
    {
        cout<<"You have one chance in ";
        cout<<probability(total,choices);
        cout<<" of winning.\n";
        cout<<"Next two numbers(q to quit): ";
    }
    cout<<"bye\n";
    system("pause");
    return 0;
}
//the following function calculates the probability of picking picks
//numbers coorectly from numbers choices
long double probability(unsigned numbers,unsigned picks)
{
    long double result = 1.0;
    long double n;
    unsigned p;

    for(n = numbers,p = picks;p>0;n--,p--)
    {
        result = result * n / p;  
    }
    return result;
}